﻿using System;
using UnityEngine;
using UnityEngine.InputSystem;

namespace DefaultNamespace
{
    public class InputReader : MonoBehaviour, Controls.IPlayerActions
    {
        public event Action JumpEvent;
        public event Action DodgeEvent;
        
        public Vector2 MovementValue { get; private set; }
        
        private Controls controls;
        private void Start()
        {
            controls = new Controls();
            controls.Player.SetCallbacks(this);
            
            controls.Player.Enable();
        }

        private void OnDestroy()
        {
            controls.Player.Disable();
        }

        public void OnJump(InputAction.CallbackContext context)
        {
            // IF NO PRESSED RETURN
            if (!context.performed)
                return;
            
            Debug.Log("OnJump");
            JumpEvent?.Invoke();
        }

        public void OnDodge(InputAction.CallbackContext context)
        {
            if (!context.performed)
                return;
            
            Debug.Log("OnDodge");
            DodgeEvent?.Invoke();
        }

        public void OnMove(InputAction.CallbackContext context)
        {
            MovementValue = context.ReadValue<Vector2>();
        }

        public void OnLook(InputAction.CallbackContext context)
        {
            
        }
    }
}